#include "PersonLinkedList.h"


PersonLinkedList::PersonLinkedList(void)
{
	this->head =NULL;
}


PersonLinkedList::~PersonLinkedList(void)
{
}

void PersonLinkedList::insert(string name, int age)
{
	Person *newNode = new Person;
    newNode->name = name;
    newNode->age = age;
    newNode->next = this->head;
    this->head = newNode;
}

void PersonLinkedList::display()
{
	Person *temp = this->head;

    while(temp!=NULL)
    {
        cout<<"Person's Name : "<< temp->name <<" \t Person's Age : "<<temp->age<<endl;
        temp = temp->next;
    }
	cout<<endl;
}

int PersonLinkedList::getAge(string name)
{
	Person *temp = this->head;

    while(temp!=NULL)
    {
        if(temp->name.compare(name)==0)
        {
            return temp->age;
        }
        temp = temp->next;
    }
    cout<<"Error, person not found"<<endl;
    return -1;
}

void PersonLinkedList::deleteMostRecent()
{
	Person *temp = this->head;
    head = head->next;
    delete temp; // Delete the person from memory, free up the space
}